package com.example.controller;

import com.example.anno.LogOperation;
import com.example.pojo.Emp;
import com.example.pojo.EmpQueryParam;
import com.example.pojo.EmpResult;
import com.example.pojo.Result;
import com.example.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 员工管理的控制器
 */

@RestController
public class EmpController {
    @Autowired
    private EmpService empService;
@LogOperation
    @GetMapping(value = "/emps")
    public Result page(EmpQueryParam empQueryParam) {
        System.out.println("接受到请求参数:" + empQueryParam);
        EmpResult<Emp> empResult = empService.page(empQueryParam);
        return Result.success(empResult);

    }

    /**
     * 添加员工
     */
    @LogOperation
    @PostMapping(value = "/emps")
    public Result save(@RequestBody Emp emp) {
        // log.info("请求参数emp: {}", emp);
        empService.save(emp);
        return Result.success();
    }
    /**
     * 批量删除员工
     */
    @DeleteMapping(value = "/emps")
    public Result delete(@RequestParam List<Integer> ids){
        empService.deleteByIds(ids);
        return Result.success();
    }

    /**
     * 查询回显
     */
    @LogOperation
    @GetMapping("emps/{id}")
    public Result getInfo(@PathVariable Integer id){

        Emp emp  = empService.getInfo(id);
        return Result.success(emp);
    }
    /**
     * 更新员工信息
     */
    @PutMapping("/emps")
    public Result update(@RequestBody Emp emp){

        empService.update(emp);
        return Result.success();
    }

}


